<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>文件上传下载示例</title>
</head>

<body>
  <div>
    <div>
      <input type="file" id="file" multiple>
      <button type="button" id="uploadBtn">上传文件</button>
    </div>
    <label id="lbInfo"></label>
  </div>
  <div>
    <span>点击下载下面的文件</span>
    <div>
      <a href="/download?filename=demo.txt">demo.txt</a>
    </div>
    <div>
      <a href="/download?filename=logo.png">logo.png</a>
    </div>
  </div>
  <script>
    var fileInput = document.getElementById('file');
    var uploadBtn = document.getElementById('uploadBtn');
    var lbInfo = document.getElementById('lbInfo');
    uploadBtn.addEventListener('click', function () {
      lbInfo.innerText = ""
      var file = fileInput.files[0];
      var formData = new FormData();
      formData.append('file', file);

      var xhr = new XMLHttpRequest();
      xhr.open('POST', '/upload', true);
      xhr.onload = function () {
        if (xhr.status === 200) {
          lbInfo.innerText = "上传成功"
        }
      };

      xhr.send(formData);
    });
  </script>
</body>

</html>